$(function () {
  //登录状态标识
  const login_state = "LOGIN_STATE";
  //cookie中获取登录状态
  let state = getCookie(login_state);
  //cookie中有登录的状态标识且标识中的值OK,直接跳转首页
  if (state && state == "OK") {
    $(".logout").show();
    let user = localStorage.getItem("user");
    if (!user) {
      clearCookie(login_state);
      location.reload();
    }
    user = JSON.parse(user);
    if (user.user_img) $(".user_img").attr("src", user.user_img);
    if (user.user_nickname)
      $(".user_nickname").text(user.user_nickname).next(".link-right").hide();

    $(".myorder").click(() => {
      location.href = "../html/myorder.html";
    });
  } else {
    $(".user_nickname").click(() => {
      location.href = "../html/login.html";
    });
  }

  $(".btn-logout").click((e) => {
    e.preventDefault();
    clearCookie(login_state);
    localStorage.setItem("user", "");
    new Model({
      title: "信息",
      content: "退出成功",
      showCancel: false,
      isDrag: true,
      skin: "tan" /* 主题色 "#20222A"|"#1E9FFF"|"tan" */,
      confirmCallbak: function () {
        this.close();
      },
    }).init();
    setTimeout(() => {
      location.href = "../html/login.html";
    }, 1500);
  });

  $(".footer .title .item")
    .not(".active")
    .on("click", function () {
      $(".footer .title .item").removeClass("active");
      $(this).addClass("active");
      let href = $(this).attr("data-href");
      location.href = href;
    });
});
